<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>
<d:resource root="${ctx.resource}/build" type="script" src="js/config.js">
  <script src="${ctx.resource}/js/vendor/require.js"></script>
  <script>
    require.config({
      urlArgs: "bust=v1.1.1",
      baseUrl: '${ctx.resource}/js',
      paths: {
        'zepto': 'vendor/zepto',
        'sui': 'vendor/sm',
        'ejs': 'vendor/ejs',
        /* 'icon': 'http://at.alicdn.com/t/font_640598_rssdzbyrd95rvn29.js http://at.alicdn.com/t/font_640598_nfvrlkhjwwhilik9', */
        'icon': 'http://at.alicdn.com/t/font_640598_b9l5su44xwwv1jor',
        'smExtend': 'vendor/sm-extend',
        'smCity': 'vendor/sm-city',
        'underscore': 'vendor/underscore',
        'handlebars': 'vendor/handlebars.amd',
        'JST': 'template/JST',
        'text': 'vendor/text',
        'showdown': 'vendor/showdown.min',
        'qrcode': 'vendor/qrcode.min',
        'wx': 'http://res.wx.qq.com/open/js/jweixin-1.2.0',
        'wxshare': 'wxshare',
        'jqCountdown': 'component/jquery-countdown',
        'countDown': 'component/countdown',
        'errorImg': 'component/error-image',
        'submitForm': 'component/submitform'
      },
      shim: {
        'zepto': { exports: '$'},
        'sui': { deps: ['zepto'] },
        'smExtend': { deps: ['zepto','sui'] },
        'smExtend': { deps: ['zepto','smCity'] },
        'errorImg': { deps: ['zepto'] },
        'submitForm': { deps: ['zepto'] }
      },
      deps: ['zepto', 'sui', 'icon'],
      callback: function($) {
        $.init()
      }
    })
  </script>
</d:resource>
<script type="text/javascript">
  (function(w) {
    w.__CTX__ = {
      domain: '${ctx.domain}',
      root: '${ctx.host}',
      resource: '${ctx.resource}',
      share: function(url, data, success, fail) {
        $.ajax({
          type: 'POST',
          url: url,
          data: data
        }).done(function(data) {
          console.log(data);
          data = typeof data === 'String' ? JSON.parse(data) : data
          if(parseInt(data.code) == 0) {  
            console.log("share saved success");
            success && success();
          } else {
            console.log("share saved faild");
            fail && fail();
          }
        }).fail(function() {
          console.log("failed to save share record");
          fail && fail();
        })
      }
    }
  })(window)
</script>
